package com.itheima.a08Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test4 {
    public static void main(String[] args) {
        //制作点名系统
        //每个元素只出现一次
        //1.创建集合
        ArrayList<String> list1 = new ArrayList<>();
        //2.添加元素
        Collections.addAll(list1, "张三", "李四", "王五", "赵六", "老七", "老八", "山炮", "陈晨", "飞扬", "土豆");
        //3.创建临时集合
        ArrayList<String> list2 = new ArrayList<>();
        //打乱结合中元素的顺序
        Collections.shuffle(list1);

        //嵌套for循环进行遍历集合
        for (int i = 0; i < 10; i++) {
            System.out.println("====" + i + "============");

            //计算出list1的长度
            int count = list1.size();
            for (int j = 0; j < count; j++) {
                //生成随机索引
                Random r = new Random();
                int index = r.nextInt(list1.size());
                //删除元素并获取
                String name = list1.remove(index);
                //添加到list2集合中
                list2.add(name);
                //输出打印
                System.out.println(name);
            }
            //走到这里list1为空
            //list2集合为满
            list1.addAll(list2);
            list2.clear();
        }

    }
}
